package cn.nsu.douban.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sun.mail.handlers.message_rfc822;

import cn.nsu.douban.dao.dao.IMovieDao;
import cn.nsu.douban.entity.MovieInfo;
import cn.nsu.douban.service.IMovieService;

@Service
@Transactional
public class IMovieServiceImpl implements IMovieService {

	  @Resource
	  private IMovieDao  iMovieDao;
	public void setiMovieDao(IMovieDao iMovieDao) {
		this.iMovieDao = iMovieDao;
	}
	@Override
	public Integer getMoveiIsHotCount() {
		return iMovieDao.AllCount();
	}
	@Override
	public List<MovieInfo> getAll(Integer pageNum, Integer pageSize) {

		return iMovieDao.getAll(pageNum, pageSize);
	}
	@Override
	public MovieInfo getByMid(Integer mid) {
		return iMovieDao.getByMovieId(mid);
	}
	@Override
	public List<MovieInfo> getMovieInfoByName(String search_text) {
		return iMovieDao.getMovieInfoByNmae(search_text);
	}
	@Override
	public List<MovieInfo> findMovieByDate() {
		return iMovieDao.findMovieByDate();
	}
	@Override
	public void updateMovieInfoById(String moid,Integer pf) {
     
	     MovieInfo movieInfo = iMovieDao.getMovieInfoById(Integer.parseInt(moid));
         movieInfo.setScore(movieInfo.getScore()+pf); 
	}
	@Override
	public List<MovieInfo> getAll() {
		return iMovieDao.getAll();
	}
	@Override
	public void updateMovieInfo(MovieInfo mi) {
/*     Integer id = mi.getId();
    MovieInfo  movieInfo=iMovieDao.getMovieInfoById(id);
		  movieInfo.setBianju(mi.getBianju());
		  movieInfo.setDate(mi.getDate());
		  movieInfo.setDirector(mi.getDirector());
		  movieInfo.setImagpath(mi.getImagpath());
		  movieInfo.setInfo(mi.getInfo());
		  movieInfo.setIshow(mi.getIshow());*/
		  iMovieDao.update(mi);
	}
	@Override
	public void deleteMovie(MovieInfo mInfo) {
     iMovieDao.delete(mInfo);		
	}
	@Override
	public MovieInfo getMovieInfoById(Integer mid) {
   
	   return iMovieDao.getMovieInfoById(mid);	     
	}
	@Override
	public void save(MovieInfo mi) {
     
		 iMovieDao.save(mi);
	}
	@Override
	public void deleteMovieByDuoId(String[] ids) {
		
		for(int i=0;i<ids.length;i++){
		 MovieInfo movieInfoById = iMovieDao.getMovieInfoById(Integer.parseInt(ids[i]));
		 iMovieDao.delete(movieInfoById);
		}
		 System.out.println("删除完毕");
	}
	  
}
